/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View;

import java.util.ArrayList;
import java.io.*;
import javax.swing.JFileChooser;
/**
 *
 * @author Farrar
 */
public class saveGame {

    String data;

    public void save(int rows, int columns, ArrayList<Integer> Uppers, ArrayList<Integer> Downers, String name, int position) {
        data = name + ";" + Integer.toString(columns) + ";" + Integer.toString(rows) + ";" + Integer.toString(position);
        for (int h = 1; h < Uppers.size(); h++) {
            data = data + Uppers.get(h).toString() + "," + Downers.get(h).toString() + ";";
        }
        data = data + "\n";
        JFileChooser choose=new JFileChooser();
        File file=choose.getSelectedFile();
        String filename = "save.txt";
        ArrayList<String> saves = new ArrayList<String>();

        try {
            FileReader reader = new FileReader(file);
            BufferedReader buffer = new BufferedReader(reader);
            while (buffer.ready()) {
                String string_from_file = buffer.readLine();
                saves.add(string_from_file);
            }
            buffer.close();
        } //catch possible errors
        catch (Exception e) {
        }

        for (int i = 0; i < saves.size(); i++) {
            data = data + saves.get(i) + "\n";
        }
        try {
            FileWriter writer = new FileWriter(file);
            writer.write(data);
            writer.close();
        } catch (IOException e) {
        }
    }
}